package com.ygqh.baby.model;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class PrizeItemCatchWaWa {
	public final static Integer[] first = { 1, 2, 3 };
	public final static Integer[] second = { 4, 5 };
	public final static Integer[] third = { 6, 7, 8, 9, 10 };
	public final static Integer[] fourth = { 11, 12, 13, 14, 15 };
	public final static Integer[] fifth = { 16, 17, 18, 19, 20, 21, 22 };

	public final static Integer[][] grades = { first, second, third, fourth, fifth };

	public static Integer getGradeTimes(Integer count) {

		for (int i = 0; i < grades.length; i++) {
			Integer[] grade = grades[i];
			List<Integer> asList = Arrays.asList(grade);
			if (asList.contains(count)) {
				return i + 1;
			}

		}
		return count;
	}

	public static Boolean getPrize(Integer gradeTimes, Integer drawCount, BigDecimal thisRate) {
		Boolean flag = null;
		switch (gradeTimes) {
		case 1:
			if (thisRate.compareTo(new BigDecimal("0.2")) >= 0) {
				flag = false;
			} else if (drawCount == 3) {
				flag = true;
			}
			break;
		case 2:
			if (thisRate.compareTo(new BigDecimal("0.4")) >= 0) {
				flag = false;
			} else if (drawCount == 5) {
				flag = true;
			}
			break;
		case 3:
			if (thisRate.compareTo(new BigDecimal("0.6")) >= 0) {
				flag = false;
			} else if (drawCount == 10) {
				flag = true;
			}
			break;
		case 4:
			if (thisRate.compareTo(new BigDecimal("0.8")) >= 0) {
				flag = false;
			} else if (drawCount == 15) {
				flag = true;
			}
			break;
		case 5:
			int endTimes = getEndTimes();
			if (drawCount < 20 || thisRate.compareTo(new BigDecimal("1")) >= 0) {
				flag = false;
			} else if (drawCount == endTimes) {
				flag = true;
			}

			break;

		}
		if (flag == null && gradeTimes <= 5) {
			Random random = new Random();
			flag = random.nextBoolean();
		} else if (gradeTimes > 5 && thisRate.compareTo(new BigDecimal("1.00")) < 0) {
			flag = true;
		} else if (flag == null) {
			flag = false;
		}

		return flag;
	}

	private static int getEndTimes() {
		Random random = new Random();
		int nextInt = 0;
		while (nextInt < 18) {
			nextInt = random.nextInt(22);

		}
		return nextInt;
	}

}
